const express = require('express');
const router = express.Router();
const bookController = require('../controllers/bookController');
const authenticateToken = require('../middleware/auth').authenticateToken;
const authenticateAdmin = require('../middleware/auth').authenticateAdmin;
const { adminLogger } = require('../middleware/adminLogger');

// 公共接口 - 获取书籍列表和详情
router.get('/', bookController.getList);
router.get('/categories', bookController.getCategories);
router.get('/:id', bookController.getDetail);

// 管理员接口 - 需要管理员权限
router.post('/',
  authenticateAdmin,
  adminLogger('book_create', '创建书籍'),
  bookController.create
);

router.put('/:id',
  authenticateAdmin,
  adminLogger('book_update', '更新书籍'),
  bookController.update
);

router.delete('/:id',
  authenticateAdmin,
  adminLogger('book_delete', '删除书籍'),
  bookController.delete
);

module.exports = router;